<template>
    <div class="app-container">
      <div class="mapDiv">
        <!--地图-->
        <CasualtiesEstimate
          :shpLegendList="shpLegendList"
          :shpDataList="fastSeismicInfluenceList"
          :geomList="geomList"
          :openInfluenceFieldButton="openInfluenceFieldButton"
          @seismicInfluenceSelect="seismicInfluenceSelect"
          @EstimateResult="EstimateResult"
        />
        <div class="currentEventDiv0">
          <!--快速生成地震影响场面板-->
          <el-form ref="addRef" label-width="20px" :model="form" :rules="rules">
            <!-- <el-row style="margin-bottom: 30px;">
              <el-col :span="24"> -->
                <el-form-item label="">
                  <el-radio-group v-model="form.type" class="ml-4" @change="changeRadio">
                    <el-radio label="1" size="large">受伤</el-radio>
                    <el-radio label="2" size="large">死亡</el-radio>
                  </el-radio-group>
                </el-form-item>
              <!-- </el-col>
            </el-row> -->
          </el-form>
        </div>
        <div v-show="showFastSeismicInfluenceDivBool" class="currentEventDiv">
          <!--快速生成地震影响场面板-->
          <el-form ref="addRef" label-width="100px" :model="form" :rules="rules">
            <el-row style="margin-bottom: 30px;">
              <el-col :span="24">
                <el-form-item v-if="false" label="影响场版本号" required>
                  <el-input v-model="form.influenceVersion" placeholder="请选择" readonly style="width:200px" />
                </el-form-item>
                <!-- <el-form-item label="建筑物数据" prop="buildingData" required>
                  <el-input v-model="form.buildingData" placeholder="请选择" readonly style="width:200px" />
                  <el-button @click="selectBuildingData">选择</el-button>
                </el-form-item> -->
                <el-form-item label="人口数据" prop="demographicData" required>
                  <el-input v-model="form.demographicData" placeholder="请选择" readonly style="width:200px" />
                  <el-button @click="selectDemographicData">选择</el-button>
                </el-form-item>
                <el-form-item label="选择模型" prop="modelData" required>
                  <el-input v-model="modelName" placeholder="请选择" readonly style="width:200px"/>
                  <el-button @click="selectModel">选择</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <div style="text-align: center;margin-top: -20px;margin-bottom: 10px;">
            <el-button @click="createFastSeismicInfluence" type="primary">估计</el-button>
          </div>
        </div>
        <!--快速生成地震影响场版本信息列表-->
        <el-dialog v-model="showFastSiVersionTableBool" title="快速影响场版本选择" width="900px" append-to-body @close="closeVersionSelectDialog">
          <div style="padding:10px;">
            <el-table v-loading="tableLoading" :data="fastSiVersionList" stripe>
              <el-table-column label="单选" width="55px">
                <template #default="scope">
                  <el-radio :label="scope.row.fvId" v-model="selectRadio"
                            @click.native.stop.prevent="getCurrentRow(scope.row)">&nbsp;</el-radio>
                </template>
              </el-table-column>
              <el-table-column label="地震影响场图编号" align="center" prop="versionCode" width="200" />
              <el-table-column label="长轴方向" align="center" prop="angle" width="100" />
              <el-table-column label="生成人" align="center" prop="createUserName" width="100" />
              <el-table-column label="生成时间" align="center" prop="createTime" width="100" />
              <el-table-column label="中心点经度" align="center" prop="longitude" width="100" />
              <el-table-column label="中心点纬度" align="center" prop="latitude" width="100" />
              <el-table-column label="震级" align="center" prop="earthquakeLevel" width="100" />
            </el-table>
            <pagination v-show="total > 0" :total="total" v-model:page="queryParams.page" v-model:limit="queryParams.rows"
                        @pagination="getFastSiVersionList" />
          </div>
          <template #footer>
            <div class="dialog-footer">
              <el-button type="primary" @click="submitVersionSelect">确 定</el-button>
            </div>
          </template>
        </el-dialog>
        <!--建筑物数据信息列表-->
        <el-dialog v-model="buildingDataTableBool" title="建筑物数据信息列表" width="900px" append-to-body @close="closeVersionSelectDialog1">
          <div style="padding:10px;">
            <el-table v-loading="tableLoading" :data="buildingDataList" stripe>
              <el-table-column label="单选" width="55px">
                <template #default="scope">
                  <el-radio :label="scope.row.id" v-model="selectRadio1"
                            @click.native.stop.prevent="getCurrentRow1(scope.row)">&nbsp;</el-radio>
                </template>
              </el-table-column>
              <el-table-column label="数据名称" align="center" prop="dataName" width="200" />
              <el-table-column label="版本号" align="center" prop="versionCode" width="100" />
              <el-table-column label="数据类型" align="center" prop="dataType" width="100" />
              <el-table-column label="版本范围" align="center" prop="dataRange" width="100" />
              <el-table-column label="版本说明" align="center" prop="versionDesc" width="100" />
              <el-table-column label="数据说明" align="center" prop="dataDesc" width="100" />
              <el-table-column label="版本日期" align="center" prop="versionTime" width="100" />
              <el-table-column label="上传人" align="center" prop="uploadUser" width="100" />
              <el-table-column label="上传日期" align="center" prop="uploadTime" width="100" />
            </el-table>
            <pagination v-show="total1 > 0" :total="total1" v-model:page="queryParams1.page" v-model:limit="queryParams1.rows"
                        @pagination="selectBuildingData" />
          </div>
          <template #footer>
            <div class="dialog-footer">
              <el-button type="primary" @click="selectBuildingDataButton">确 定</el-button>
            </div>
          </template>
        </el-dialog>
        <!--人口数据信息列表-->
        <el-dialog v-model="demographicDataTableBool" title="人口数据信息列表" width="900px" append-to-body @close="closeVersionSelectDialog2">
          <div style="padding:10px;">
            <el-table v-loading="tableLoading" :data="demographicDataList" stripe>
              <el-table-column label="单选" width="55px">
                <template #default="scope">
                  <el-radio :label="scope.row.id" v-model="selectRadio2"
                            @click.native.stop.prevent="getCurrentRow2(scope.row)">&nbsp;</el-radio>
                </template>
              </el-table-column>
              <el-table-column label="数据名称" align="center" prop="dataName" width="200" />
              <el-table-column label="版本号" align="center" prop="versionCode" width="100" />
              <el-table-column label="数据类型" align="center" prop="dataType" width="100" />
              <el-table-column label="版本范围" align="center" prop="dataRange" width="100" />
              <el-table-column label="版本说明" align="center" prop="versionDesc" width="100" />
              <el-table-column label="数据说明" align="center" prop="dataDesc" width="100" />
              <el-table-column label="版本日期" align="center" prop="versionTime" width="100" />
              <el-table-column label="上传人" align="center" prop="uploadUser" width="100" />
              <el-table-column label="上传日期" align="center" prop="uploadTime" width="100" />
            </el-table>
            <pagination v-show="total2 > 0" :total="total2" v-model:page="queryParams2.page" v-model:limit="queryParams2.rows"
                        @pagination="selectDemographicData" />
          </div>
          <template #footer>
            <div class="dialog-footer">
              <el-button type="primary" @click="selectDemographicDataButton">确 定</el-button>
            </div>
          </template>
        </el-dialog>
        <!--人员伤亡模型信息列表-->
        <el-dialog v-model="modelDataTableBool" title="人员伤亡模型信息列表" width="900px" append-to-body @close="closeVersionSelectDialog2">
          <div style="padding:10px;">
            <el-table v-loading="tableLoading" :data="modelDataList" stripe>
              <el-table-column label="单选" width="55px">
                <template #default="scope">
                  <el-radio :label="scope.row.id" v-model="selectRadio3"
                            @click.native.stop.prevent="getCurrentRow3(scope.row)">&nbsp;</el-radio>
                </template>
              </el-table-column>
              <el-table-column label="模型名称" align="center" prop="modelName" width="200">
                <template #default="scope">
                  <el-button type="text" @click="handleDetail(scope.row)">{{scope.row.modelName}}</el-button>
                </template>
              </el-table-column>
              <el-table-column label="省" align="center" prop="province" width="100" />
              <el-table-column label="市" align="center" prop="cityAll" width="100" />
              <el-table-column label="是否默认" align="center" prop="isDefault">
                <template #default="scope">
                  <span v-if="scope.row.isDefault=='0'">否</span>
                  <span v-if="scope.row.isDefault=='1'">是</span>
                </template>
              </el-table-column>
              <el-table-column label="维护人" align="center" prop="createUserName" width="100" />
              <el-table-column label="维护人所属单位" align="center" prop="orgName" width="100" />
            </el-table>
            <pagination v-show="total3 > 0" :total="total3" v-model:page="queryParams3.page" v-model:limit="queryParams3.rows"
                        @pagination="selectModel" />
          </div>
          <template #footer>
            <div class="dialog-footer">
              <el-button type="primary" @click="selectModelButton">确 定</el-button>
            </div>
          </template>
        </el-dialog>
            <!-- 添加或修改区县致死性差异性对话框 -->
    <el-dialog title="人员伤亡计算模型" v-model="openModel" width="850px" append-to-body>
      <el-form ref="casualtiesRef" :model="formModel" label-width="120px">
      	<p class="dialogTitle">{{title}}</p>
 				<el-row>
   				<el-col :span="12">
	       		<el-form-item label="模型名称" prop="modelName" v-if="isCopy">
	       			{{formModel.modelName}}		          
		        </el-form-item>
		        <el-form-item label="模型名称" prop="modelName" v-else>
	       			<el-input v-model="formModel.modelName" placeholder="请输入模型名称" />		          
		        </el-form-item>
	       	</el-col>
	       	<el-col :span="12">
	       		<el-form-item label="是否默认" prop="" v-if="isCopy">
	       			{{formModel.isDefault=='0'?'否':'是'}}		          
		        </el-form-item>
		        <el-form-item label="是否默认" prop="" v-else>
	       			<el-select v-model="formModel.isDefault" disabled style="width: 100%;">
	               <el-option
	                v-for="item in [
	                  { value: '0', label: '否' },
	                  { value: '1', label: '是' },
	                ]"
	                :key="item.value"
	                :label="item.label"
	                :value="item.value"
	              >
              </el-option>
	           	</el-select>	          
		        </el-form-item>
	       	</el-col>
	       	
   			</el-row>
 				<el-row>
	  			<el-col :span="24">
		        <el-form-item label="地区" prop="" v-if="isCopy||isEditDefault">
		          {{formModel.province}} - {{formModel.city}}
		        </el-form-item>
		        <el-form-item label="地区" prop="" v-else>
		          
		          <el-form-item label="省" prop="provinceId" label-width="50px">
			          <el-select v-model="formModel.provinceId" placeholder="请输入省" @change="chooseFormProvince"  style="width: 160px;">
		           		<el-option
		                v-for="item in provinceFormData"
		                :key="item.id"
		                :label="item.name"
		                :value="item.id">
		            	</el-option>
		        		</el-select>
	        		</el-form-item>
	        		<el-col :span="16">
	        			<el-form-item label="市" prop="cityId" label-width="50px">
	        				<el-radio-group v-model="radio" @change="chooseRadio">
							      <el-radio label="1">全部</el-radio>
							      <el-radio label="2">
							      	<el-select v-model="formModel.cityId" placeholder="请输入市" multiple collapse-tags :disabled="isCityEdit" style="width: 200px;">
					           		<el-option
					                v-for="item in cityFormData"
					                :key="item.id"
					                :label="item.name"
					                :value="item.id">
					            	</el-option>
					        		</el-select>
							      </el-radio>
							    </el-radio-group>
		  					</el-form-item>
  						</el-col>
	        		
			          

		        </el-form-item>
		    	</el-col>
	       
       	</el-row>
   			<el-row>
   				<el-col :span="12">
	       		<el-form-item label="维护人" prop="">
	       			{{formModel.createUserName}}		          
		        </el-form-item>
	       	</el-col>
	       	<el-col :span="12">
	       		<el-form-item label="维护人单位" prop="">
	       			{{formModel.orgName}}		          
		        </el-form-item>
	       	</el-col>
	       	
   			</el-row>
   			
 				<el-row>
					<el-col :span="6" class="tab-title">
						建筑物破坏评估模型
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12" :offset="6">
						<span style="font-size: 16px;font-weight: bold;font-style: italic;">F(I) = ∑<sub>n</sub> ∑<sub>s</sub> ∑<sub>j</sub> P [<span style="position: absolute;top: -15px;">D<sub>j</sub></span>—<span style="position: absolute;top: 12px;margin-left: -10px;">I</span>] * B<sub>s</sub> </span><br/><br/>
						式中：<br/>
						I	--表示地震烈度；<br/>
						N	--表示烈度圈I内的单元数据（公里格网）；<br/>
						F(I)--表示在烈度I内，各类建筑的每类破坏面积之和；<br/>
						P[D<sub>j</sub>/I]--表示s类建筑在烈度I，j类破坏比率；<br/>
						B<sub>s</sub>	--表示I烈度，每个单元中s类建筑的面积。<br/>
					</el-col>
				</el-row>
        <el-row>
					<el-col :span="6" class="tab-title">
						根据损坏比计算死亡比
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12" :offset="6" v-if="isCopy">
						<span style="font-size: 16px;font-weight: bold;font-style: italic;">log RD = 12.479 A<sup>0.1</sup>-13.3 </span><br/><br/><br/>
						RD为死亡比，A为房屋毁坏比（房屋毁坏面积/房屋总面积）<br/>
						
					</el-col>
					<el-col :span="12" :offset="6" v-else>
						<span style="font-size: 16px;font-weight: bold;font-style: italic;">log RD = 
						<el-form-item prop="smrsNumber1" label-width="0" style="display: inline-block;">
							<el-input v-model="formModel.smrsNumber1" placeholder="保留三位小数" style="width: 110px;" />
						</el-form-item>
							 A<sup>0.1</sup>- 
					 	<el-form-item prop="smrsNumber2" label-width="0" style="display: inline-block;">
							 <el-input v-model="formModel.smrsNumber2" placeholder="保留两位小数" style="width: 110px;" />
						</el-form-item>
						</span> <br/><br/><br/>
						RD为死亡比，A为房屋毁坏比（房屋毁坏面积/房屋总面积）<br/>
						
					</el-col>
				</el-row>
        <el-row>
					<el-col :span="6" class="tab-title">
						计算死亡人数
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12" :offset="6" v-if="isCopy">
						<span style="font-size: 16px;font-weight: bold;font-style: italic;">D = ∑<sub style="position: absolute;top: 20px;margin-left: -6px;">i</sub>（RD<sub>i</sub> * S<sub>i</sub> * P<sub>t</sub>）</span><br/><br/>
						D为评估区死亡人数，RD<sub>i</sub>为公里格网在i烈度下的死亡率，
						S<sub>i</sub> 为人口变化特征修正值（系数）（区间范围（0,10]），
						计算死亡人数时，考虑灾区人口时空变化特征作为修正，
						主要考虑外出务工比例及外出和回家规律、景点旺季游客规模和淡季游客规模等关键因素。
						P<sub>t</sub>为每个公里格网的总人数。<br/>
						
					</el-col>
					<el-col :span="12" :offset="6" v-else>
						<span style="font-size: 16px;font-weight: bold;font-style: italic;">D = ∑<sub style="position: absolute;top: 20px;margin-left: -6px;">i</sub>（RD<sub>i</sub> * 
						<el-form-item prop="deathNumber" label-width="0" style="display: inline-block;">	
							<el-input v-model="formModel.deathNumber" placeholder="" style="width: 100px;" />
						</el-form-item>
							* P<sub>t</sub>）</span><br/><br/>
						D为评估区死亡人数，RD<sub>i</sub>为公里格网在i烈度下的死亡率，
						S<sub>i</sub> 为人口变化特征修正值（系数）（区间范围（0,10]），
						计算死亡人数时，考虑灾区人口时空变化特征作为修正，
						主要考虑外出务工比例及外出和回家规律、景点旺季游客规模和淡季游客规模等关键因素。
						P<sub>t</sub>为每个公里格网的总人数。<br/>
						
					</el-col>
				</el-row>
        <el-row>
					<el-col :span="6" class="tab-title">
						计算受伤人数
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12" :offset="6" v-if="isCopy">
						<span style="font-size: 16px;font-weight: bold;font-style: italic;">F = D * C </span><br/><br/>
						F为受伤人数，C为受伤人数与死亡人数的比例，一般为3到5倍。<br/>
						
					</el-col>
					<el-col :span="12" :offset="6" v-else>
						<span style="font-size: 16px;font-weight: bold;font-style: italic;">F = D * 
						<el-form-item prop="injuries" label-width="0" style="display: inline-block;">
							<el-input v-model="formModel.injuries" placeholder="[3,5]" style="width: 80px;" /> 
						</el-form-item>	
						</span><br/><br/>
						F为受伤人数，C为受伤人数与死亡人数的比例，一般为3到5倍。<br/>
					</el-col>
				</el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button plain @click="openModel=false">取 消</el-button>
        </div>
      </template>
    </el-dialog>
        <!--评估结果图层图例-->
        <div v-if="showEvaluateResultBool" class="new-evaluateResultDiv">
          <div style="text-align: center;">
            <span style="font-size: 14px;font-weight: bold;color: rgb(16, 124, 229);">图例</span>
          </div>
          <template v-for="item in evaluateResultLegendData">
            <div>
              <div style="padding-left: 8px;"><div style="width:25px;" :style="{'background-color': item.color}" class="new-legendDiv-polygon"></div></div>
              <span>{{ item.value }}</span>
            </div>
          </template>
        </div>
      </div>
    </div>
</template>
  
<script setup name="casualtiesEstimate">
//地图
import CasualtiesEstimate from '@/map/fastDisasterAnalysis/casualtiesEstimate/indexMap.vue';
import { countEqIntensity, getFastSeismicInfluenceListByFvId, getFastSiVersionByFvId,
  getFastSiVersionListByXsemId,updateFastSiVersion,delFastSiVersion,countSurTaskManageByType,setSelectFastSiVersion,getFastSiVersionByXsemId } from "@/api/fastDisasterAnalysis/fastSeismicInfluence/intensity";
import { getDetail } from "@/api/comprehensiveInformation/seismicEvents.js"
import { getModelCasualties,getVersion,casualtiesGetModelData,getPopulationResult,chooseModel,casualtiesCountIntensityAndStructureOfArea,savePbeInjuries,casualtiesEvaluate,getModelData} from "@/api/fastDisasterAnalysis/evaluationCalculation.js"
import { getProvince , getChildArea} from "@/api/system/division"
const { proxy } = getCurrentInstance();
import useEventStore from "@/store/modules/event";
import { ref } from 'vue';
const currentEvent = computed(() => useEventStore().currentEvent);
const router = useRouter();
const tableLoading = ref(false);
const data = reactive({
  form: {
    type: '1',
    influenceVersion: '',
    buildingData: '',
    demographicData: '',
    modelData: '',
  },
  formModel:{

  },
  queryParams: {
    page: 1,
    rows: 10,
  },
  queryParams1: {
    page: 1,
    rows: 10,
  },
  queryParams2: {
    page: 1,
    rows: 10,
  },
  queryParams3: {
    page: 1,
    rows: 10,
  },
  rules: {
      buildingData: [{ required: true, message: "建筑物数据不能为空", trigger: "blur" }],
      demographicData: [{ required: true, message: "人口数据不能为空", trigger: "blur" }],
      modelData: [{ required: true, message: "模型不能为空", trigger: "blur" }],
  },
  shpLegendList:[
    {fullName:"Ⅴ（5度）",name:"Ⅴ",value:"5",color:"rgba(255,220,220,0.7)",show:false},
    {fullName:"Ⅵ（6度）",name:"Ⅵ",value:"6",color:"rgba(255,190,190,0.7)",show:false},
    {fullName:"Ⅶ（7度）",name:"Ⅶ",value:"7",color:"rgba(255,127,127,0.7)",show:false},
    {fullName:"Ⅷ（8度）",name:"Ⅷ",value:"8",color:"rgba(200,40,40,0.7)",show:false},
    {fullName:"Ⅸ（9度）",name:"Ⅸ",value:"9",color:"rgba(168,0,0,0.7)",show:false},
    {fullName:"Ⅹ（10度）",name:"Ⅹ",value:"10",color:"rgba(140,0,0,0.7)",show:false},
    {fullName:"Ⅺ（11度）",name:"Ⅺ",value:"11",color:"rgba(105,0,0,0.7)",show:false},
    {fullName:"Ⅻ（12度）",name:"Ⅻ",value:"12",color:"rgba(80,0,0,0.7)",show:false},
  ],//灾区范围图例列表
})
const { form,formModel,queryParams,shpLegendList,queryParams1,rules,queryParams2,queryParams3 } = toRefs(data)
const modelDataTableBool = ref(false)
const showEvaluateResultBool = ref(false)
const modelDataList = ref([])
const selectRadio3 = ref('')
const total3 = ref(0)
const beInjuredLegned = ref([
  {value: '0-10',color: 'rgba(224,116,75,0.3)'},
  {value: '10-50',color: 'rgba(235,112,55,0.3)'},
  {value: '50-100',color: 'rgba(198,112,91,0.3)'},
  {value: '100-500',color: 'rgba(163,103,104,0.3)'},
  {value: '500以上',color: 'rgba(136,95,95,0.3)'},
])
const deathLegend = ref([
  {value: '0-10',color: 'rgba(246,159,103,0.3)'},
  {value: '11-30',color: 'rgba(241,147,101,0.3)'},
  {value: '31-50',color: 'rgba(224,116,75,0.3)'},
  {value: '51-100',color: 'rgba(235,112,55,0.3)'},
  {value: '101-300',color: 'rgba(198,112,91,0.3)'},
  {value: '301-500',color: 'rgba(163,103,104,0.3)'},
  {value: '500以上',color: 'rgba(136,95,95,0.3)'},
])
//是否显示快速生成地震影响场面板
const showFastSeismicInfluenceDivBool = ref(false);
//是否显示地震影响场版本信息列表表格
const showFastSiVersionTableBool = ref(false);
const buildingDataTableBool = ref(false)
const showFsiSelectBool = ref(false);//是否显示选择快速影响场
const isInfluence = ref(false)
const openModel = ref(false)
const titleModel = ref('')
const isCopy = ref(true);
const Default = ref("1");
const radio = ref("1");
const isCityEdit = ref(true);
const isEditDefault = ref(true);
//选择地震影响场
const seismicInfluenceSelect = (val)=>{
  isInfluence.value = val
  showFsiSelectBool.value = val;
  if(val){
    showFastSiVersionTableBool.value = true;
    openInfluenceFieldButton.value = true
    // 根据事件ID查询地震影响场版本信息列表
    getFastSiVersionList();
  }else{
    showFastSiVersionTableBool.value = false;
    fastSeismicInfluenceList.value = [];
    openInfluenceFieldButton.value = false
  }
}
const EstimateResult = (val) => {
  // if(val) {
    showFastSeismicInfluenceDivBool.value = val
  // }else{

  // }
}
//地震影响场版本信息列表
const fastSiVersionList = ref([]);
const buildingDataList = ref([])
const total = ref(0);//总数
const total1 = ref(0)
// 根据事件ID查询地震影响场版本信息列表
function getFastSiVersionList(){
  let xsemId = currentEvent.value.id;
  if(xsemId){
    tableLoading.value = true;
    getFastSiVersionListByXsemId({xsemId,...queryParams.value}).then(res=>{
      fastSiVersionList.value = res.data.rows ? res.data.rows : [];
      total.value = res.data.total;
      tableLoading.value = false;
    })
  }
}
const closeInfluence = ref(false)
//确定选择快速影响场版本
const submitVersionSelect = ()=>{
  if (selectRadio.value) {
    closeInfluence.value = true
    showFastSiVersionTableBool.value = false;
    showFsiSelectBool.value = false;
    // 调查任务管理--根据类型查询事件的全部新建的评估子区数量
    countSurTaskManage();
  }else{
    fastSeismicInfluenceList.value = [];
    showFsiSelectBool.value = false;
    proxy.$modal.msgWarning("请选取版本");
  }
}
//事件ID选择的地震影响场版本信息
const selectFastSiVersion = ref({});
// 调查任务管理--根据类型查询事件的全部新建的评估子区数量
function countSurTaskManage(){
  if(selectFastSiVersion.value && currentEvent.value){
    let fvId = selectFastSiVersion.value.fvId;
    let xsemId = currentEvent.value.id;
    // 调查任务管理--根据类型查询事件的全部新建的评估子区数量
    countSurTaskManageByType({xsemId: xsemId,type: "0"}).then(res=>{
      // 调查任务管理--事件的1个快速生成地震影响场版本信息设置选择
      setSelectFastSiVersionByFvId(xsemId);
    });
  }
}
// 调查任务管理--事件的1个快速生成地震影响场版本信息设置选择
function setSelectFastSiVersionByFvId(xsemId){
  let fvId = selectRadio.value;
  if(fvId){
    selectFastSiVersion.value = selectionData.value;
    // 调查任务管理--事件的1个快速生成地震影响场版本信息设置选择
    setSelectFastSiVersion(xsemId,fvId).then(res=>{
      console.log(res);
      // 根据版本ID查询地震影响场空间数据列表
      // getFastSeismicInfluenceList(fvId);
      initFunction();//初始化
    })
  }
}
const geomList = ref({})
const evaluateResultLegendData = ref([])
function createFastSeismicInfluence() {
  getModelData({xsemId:currentEvent.value.id,}).then(resResult => {
      if(resResult.data.buildingVersion == '' || resResult.data.buildingVersion == null ) {
        proxy.$modal.msgWarning("请先进行房屋破坏评估！");
      }else{
        showEvaluateResultBool.value = true
      if(form.value.type == '1') {
        evaluateResultLegendData.value = beInjuredLegned.value
      }else{
        evaluateResultLegendData.value = deathLegend.value
      }
      if(openInfluenceFieldButton.value) {
        casualtiesGetModelData({xsemId:currentEvent.value.id,}).then(resResult1 => {
          if(resResult1.data != null ) {
            proxy.$modal.confirm("重复评估会覆盖已有评估结果，请确认是否继续？",).then(function () {
              countResult(resResult.data.buildingVersion)
            }).then(() => {
              addnfluence()
            }).catch(() => { });
          }else{
            countResult(resResult.data.buildingVersion)
          }
        })

      }else{
        proxy.$modal.msgWarning("请选取影响场版本");
      }
      }
  })
}
function countResult(buildingVersion) {
  proxy.$modal.loading('正在计算，请稍等...')
  casualtiesCountIntensityAndStructureOfArea({
    "xsemId":currentEvent.value.id,
    "populationVersion":form.value.demographicData,
    "buildingVersion":buildingVersion,
    "influenceVersion":form.value.influenceVersion,
    "fvId":selectRadio.value,
    "modelId":form.value.modelData
  }).then(res => {
    savePbeInjuries({"xsemId":currentEvent.value.id,"modelId":form.value.modelData}).then(response => {
      casualtiesEvaluate({
        "xsemId":currentEvent.value.id,
        "populationVersion":form.value.demographicData,
        "buildingVersion":buildingVersion,
        "influenceVersion":form.value.influenceVersion,
        "fvId":selectRadio.value,
        "modelId":form.value.modelData
      }).then(responseList => {
        getPopulationResult({"xsemId":currentEvent.value.id,}).then(result => {
          geomList.value = {type: form.value.type,list: result.data}
          proxy.$modal.closeLoading()
        }).catch(err => {
          proxy.$modal.closeLoading()
        })
      }).catch(err => {
          proxy.$modal.closeLoading()
        })
    }).catch(err => {
        proxy.$modal.closeLoading()
      })
  }).catch(err => {
      proxy.$modal.closeLoading()
    })
}
//初始化
function initFunction(){
  let xsemId = currentEvent.value.id;
  if(xsemId){
    // 调查任务管理--根据事件ID查询选择的地震影响场版本信息
    getSelectFastSiVersionByXsemId(xsemId);
  }
}
// 调查任务管理--根据事件ID查询选择的地震影响场版本信息
function getSelectFastSiVersionByXsemId(xsemId){
  getFastSiVersionByXsemId(xsemId).then(res=>{
    let data = res.data;
    console.log(data);
    if(data){
      selectFastSiVersion.value = data;
      //确定选择
      // getCurrentRow(data);
       //根据事件ID查询灾区范围列表
      getSeismicInfluenceArray("");
    }
  })
}
//地震影响场空间数据列表
const fastSeismicInfluenceList = ref([]);
const liduJiBieData = ref([])
//类型zqfw,事件ID
const typeCode = ref("");
//根据事件ID查询灾区范围列表
function getSeismicInfluenceArray(geom){
  let fvId = selectFastSiVersion.value.fvId;
  if (fvId) {
    //
  }else{
    return;
  }
  if (currentEvent.value) {
    let xsemId = currentEvent.value.id;
    //类型zqfw,事件ID
    typeCode.value = "zqfw,"+xsemId;
    getFastSeismicInfluenceListByFvId(fvId,geom).then(response => {
      console.log("根据事件ID查询灾区范围列表");
      console.log(response.data);
      let list = response.data;
      if(geom){//新建|修改任务前查询空间范围是否在灾区范围内
        //新建任务
        openTask();
      }else{//初始化查询灾区范围
        fastSeismicInfluenceList.value = list;
        liduJiBieData.value = list
        if(list && list.length>0){
          let legendList = shpLegendList.value;
          for(let i=0;i<legendList.length;i++){
            let val = legendList[i].value;
            for(let j=0;j<list.length;j++){
              if(val==list[j].intensity){//烈度
                legendList[i].show = true;//只显示灾区范围的烈度
                break;
              }
            }
          }
          shpLegendList.value = legendList;
        }
      }
    });
  }else{
    fastSeismicInfluenceList.value = [];
  }
}
//选择快速影响场版本
const selectionData = ref({});
const selectRadio = ref('');

//单选选择
function getCurrentRow(row) {
  debugger
  if (selectRadio.value) {
    if (selectRadio.value == row.fvId) {
      form.value.influenceVersion = ''
      selectRadio.value = ''
      selectionData.value = {};// 取消勾选就把回传数据清除
      return;
    }
  }
  form.value.influenceVersion = row.versionCode
  selectRadio.value = row.fvId;
  selectionData.value = row;
}
const selectRadio1 = ref('')
const selectionData1 = ref({});
function getCurrentRow1(row) {
  if (selectRadio1.value) {
    if (selectRadio1.value == row.id) {
      selectRadio1.value = ''
      selectionData1.value = {};// 取消勾选就把回传数据清除
      return;
    }
  }
  selectRadio1.value = row.id;
  selectionData1.value = row;
}
const selectRadio2 = ref('')
const selectionData2 = ref({});
function getCurrentRow2(row) {
  if (selectRadio2.value) {
    if (selectRadio2.value == row.id) {
      selectRadio2.value = ''
      selectionData2.value = {};// 取消勾选就把回传数据清除
      return;
    }
  }
  selectRadio2.value = row.id;
  selectionData2.value = row;
}
const selectionData3 = ref([])
function getCurrentRow3(row) {
  if (selectRadio3.value) {
    if (selectRadio3.value == row.id) {
      selectRadio3.value = ''
      selectionData3.value = {};// 取消勾选就把回传数据清除
      return;
    }
  }
  selectRadio3.value = row.id;
  selectionData3.value = row;
}
function selectBuildingDataButton() {
  buildingDataTableBool.value = false
  debugger
  if(selectionData1.value) {
    form.value.buildingData = selectionData1.value.versionCode
  }else{
    form.value.buildingData = ''
  }
}
function selectDemographicDataButton() {
  demographicDataTableBool.value = false
  debugger
  if(selectionData2.value) {
    form.value.demographicData = selectionData2.value.versionCode
  }else{
    form.value.demographicData = ''
  }
}
const modelName = ref('')
function selectModelButton() {
  modelDataTableBool.value = false
  if(selectionData3.value) {
    form.value.modelData = selectionData3.value.id
    modelName.value = selectionData3.value.modelName
  }else{
    form.value.modelData = ''
  }
}
const handleDetail=(row)=>{
  const id = row.id 
  if(row.isDefault=="1"){
  	isCopy.value = true;
  	Default.value = "1";
  	titleModel.value = "系统默认人员伤亡计算模型";
  }else{
  	isCopy.value = false;
  	Default.value = "0";
  	titleModel.value = "人员伤亡计算模型";
  }
  getModelCasualties(id).then(response => {
    formModel.value = response.data;
    openModel.value = true;
    if(formModel.value.city=="全部"){
    	radio.value = "1"
    	isCityEdit.value = true
    }else{
    	radio.value = "2"
    	isCityEdit.value = false
    }
    if(formModel.value.isDefault=="0"){
    	isEditDefault.value = true
    }else{
    	isEditDefault.value = false
    }
    
  });
}
const provinceFormData = ref([]);//表单省 
const cityFormData = ref([]);//表单市
function getProvinceFormData() {
	getProvince().then(response => {
	    provinceFormData.value = response.data;
	});
}
function chooseFormProvince(value){
	formModel.value.city = null;
	formModel.value.area = null;
	cityFormData.value = [];
	areaFormData.value = [];
	getChildArea(value).then(response => {
    cityFormData.value = response.data;
	});	
}

function chooseRadio(value){
	if(value == "2"){
		isCityEdit.value = false
		
	}else{
		isCityEdit.value = true
		formModel.value.city = "全部"
		formModel.value.cityId = ""
	}
}


//关闭选择快速影响场版本
const closeVersionSelectDialog = () =>{
  showFastSiVersionTableBool.value = false;
  showFsiSelectBool.value = false;
  if(closeInfluence.value) {
    // openInfluenceFieldButton.value = true
  }else{
    openInfluenceFieldButton.value = false
  }
  closeInfluence.value = false
}
const closeVersionSelectDialog1 = () =>{
  buildingDataTableBool.value = false;
}
const closeVersionSelectDialog2 = () =>{
  demographicDataTableBool.value = false;
}
function selectBuildingData () {
  getVersion({dataType2: 115,...queryParams1.value}).then(res => {
    buildingDataTableBool.value = true
    buildingDataList.value = res.data.list
    total1.value = res.data.total
  }).catch()
}
const demographicDataTableBool = ref(false)
const demographicDataList = ref([])
const total2 = ref(0)
function selectDemographicData() {
  getVersion({dataType2: 138,...queryParams2.value}).then(res => {
    demographicDataTableBool.value = true
    demographicDataList.value = res.data.list
    total2.value = res.data.total
  }).catch()
}
function selectModel() {
  modelDataTableBool.value = true
  tableLoading.value = true
  chooseModel({...queryParams3.value,province: '',modelName: '',city: ''}).then(res => {
    tableLoading.value = false
    modelDataList.value = res.data.rows
    total3.value = res.data.total
  }).catch()
}
function changeRadio(value) {
  getPopulationResult({"xsemId":currentEvent.value.id,}).then(result => {
    geomList.value = {type: value,list: result.data}
  }).catch()
}
const openInfluenceFieldButton = ref(false)
function addnfluence() {
  casualtiesGetModelData({xsemId:currentEvent.value.id,}).then(resResult => {
    if(resResult.data != null ) {
      form.value.buildingData = resResult.data.buildingVersion == null?'':resResult.data.buildingVersion
      form.value.influenceVersion = resResult.data.influenceVersion == null?'':resResult.data.influenceVersion
      openInfluenceFieldButton.value = true
      form.value.demographicData = resResult.data.populationVersion == null?'':resResult.data.populationVersion
      modelName.value = resResult.data.modelName == null?'':resResult.data.modelName
      form.value.modelData = resResult.data.modelId == null?'':resResult.data.modelId
      selectRadio.value = resResult.data.fvId == null?'':resResult.data.fvId
      getFastSeismicInfluenceListByFvId(resResult.data.fvId,'').then(response => {
        console.log("根据事件ID查询灾区范围列表");
        console.log(response.data);
        let list = response.data;
        // if(geom){//新建|修改任务前查询空间范围是否在灾区范围内
        //   //新建任务
        //   openTask();
        // }else{//初始化查询灾区范围
          fastSeismicInfluenceList.value = list;
          liduJiBieData.value = list
          if(list && list.length>0){
            let legendList = shpLegendList.value;
            for(let i=0;i<legendList.length;i++){
              let val = legendList[i].value;
              for(let j=0;j<list.length;j++){
                if(val==list[j].intensity){//烈度
                  legendList[i].show = true;//只显示灾区范围的烈度
                  break;
                }
              }
            }
            shpLegendList.value = legendList;
          }
        // }
      });
    }
  })
}
onMounted(() => {
  evaluateResultLegendData.value = beInjuredLegned.value
  showEvaluateResultBool.value = true
  setTimeout(() => {
    getPopulationResult({"xsemId":currentEvent.value.id,}).then(result => {
      geomList.value = {type: form.value.type,list: result.data}
    }).catch()
    addnfluence()
  }, 500)
  getProvinceFormData()
})
</script>
  
<style scoped lang="scss">
.mapDiv {
  position:absolute;top:0px;left:0px;width:100%;height:100%;
}
.currentEventDiv0 {
  position:absolute;top:20px;right:20px;background:rgba(255,255,255,0.8);border:1px solid gray;padding:20px 20px 0 20px;
}
.currentEventDiv {
  position:absolute;top:106px;right:20px;background:rgba(255,255,255,0.8);border:1px solid gray;padding:20px;
}
/*评估结果图层图例*/
.new-evaluateResultDiv {
  position: absolute;
  top: 68%;
  right: 0px;
  background: #fff;
  box-shadow: 0px 0px 20px rgb(0 0 0 / 20%);
  border: 1px solid #707070;
  border-radius: 4px;
  padding: 5px;
}
.new-evaluateResultDiv div {
  position: relative;
  height: 16px;
  line-height: 16px;
  font-size: 13px;
  margin: 8px;
}
.new-evaluateResultDiv div span {
  line-height: 16px;
  font-size: 13px;
}
.new-evaluateResultDiv div div {
  position: relative;
  top: 2px;
  left: 8px;
  width: 30px;
  height: 14px;
  margin: 0px !important;
  margin-right: 25px !important;
  display: inline-block;
}
</style>
  
  